package com.xy.biz.auth.controller;

import com.xy.biz.auth.domain.req.UserCodeLoginRequest;
import com.xy.biz.auth.domain.req.UserCodeRegisterRequest;
import com.xy.biz.auth.service.LogonService;
import com.xy.biz.uc.domain.req.SaveUserRequest;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("登录")
@RestController
@RequestMapping("/api/auth/logon")
public class LogonController {

    @Autowired
    private LogonService logonService;

    @Validatable
    @PostMapping(value = "/register_by_user_code")
    public Result<?> register(@RequestBody UserCodeRegisterRequest request) {
        return logonService.register(request);
    }

    @Validatable
    @PostMapping(value = "/save_user")
    public Result<?> saveUser(@RequestBody SaveUserRequest request) {
        return logonService.saveUser(request);
    }

    @Validatable
    @PostMapping(value = "/login_by_user_code")
    public Result<String> login(@RequestBody UserCodeLoginRequest request) {
        return logonService.login(request);
    }

    @Validatable
    @PostMapping(value = "/logout")
    public Result<String> logout() {
        return Result.success();
    }

}
